<template>
  <van-nav-bar
    :title="title"
    fixed
    :right-text="rightText"
    left-arrow
    @click-left="onClickLeft"
    @click-right="onClickRight"
  />
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'
const router = useRouter()
//左侧固定点击事件
const onClickLeft = () => {
  if (props.back) return props.back()
  if (history.state?.back) {
    router.back()
  } else {
    router.push('/')
  }
}
const props = defineProps<{
  title: string
  rightText: string
  back?: () => void
}>()
//子传父自定义右侧点击事件
const emit = defineEmits<{
  (e: 'click-right'): void
}>()
const onClickRight = () => {
  emit('click-right')
}
</script>

<style lang="scss" scoped>
:deep() {
  .van-nav-bar {
    //&为连接符
    &_arrow {
      font-size: 18px;
      color: var(--cp-text1);
    }
    &_text {
      font-size: 15px;
    }
  }
}
</style>
